package edu.nku.cai.dbadapter;


import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.database.Cursor;

public class ObjectDBAdapter extends BaseDBAdapter {

	public static final String KEY_NAME = "NAME", KEY_URL = "URL", KEY_ID= "ID";
	public static final String DATABASE_NAME = "Object_DB";
	public ObjectDBAdapter(Context context) {
		
		super(context, DATABASE_NAME, getTypes());
	}

	private static Map<String, String> getTypes()
	{
		Map<String, String> types = new HashMap<String, String>();
		
		types.put(KEY_ID, "INTEGER PRIMARY KEY");
		types.put(KEY_NAME, "TEXT");
		types.put(KEY_URL, "TEXT");
		
		return types;
	}
	
	public long delete(int id)
	{
		Map<String, String> where = new HashMap<String, String>();
		where.put(KEY_ID, ""+id);
		return delete(where);
	}
	
	public Object getObject(int id)
	{
		Map<String, String> where = new HashMap<String, String>();
		where.put(KEY_ID, String.valueOf(id));
		Cursor all = fetch(where);
		Object boo = null;
		if(!all.isAfterLast())
		{
			boo = objectFromCursor(all);
		}
		return boo;
	}

	private Object objectFromCursor(Cursor cur) {
		return new Object();
	}
	
	public List<Object> getObjects()
	{
		List<Object> list = new LinkedList<Object>();
		Cursor all = fetchAll();
		while(!all.isAfterLast())
		{
			list.add(objectFromCursor(all));
			all.moveToNext();
		}
		all.close();
		return list;
	}
	public long addObject(String name, String url)
	{
		Map<String, Object> values = new HashMap<String, Object>();
		values.put(KEY_NAME, name);
		values.put(KEY_URL, url);
		return createItem(values);
	}

}
